﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.IO;
using System.Drawing;
using td.Core;
using td.Core.DiscoverAddins;
using System.Threading;
using CG.Security.Principal;
using td.Core.Security;
using DevExpress.XtraEditors;

namespace td.Core
{
    public class SercurityChangePassWordCommand : td.Core.AbstractToolButtonCommand
    {
        public override void Run()
        {
            CustomPrincipal cp = (CustomPrincipal)Thread.CurrentPrincipal; ;
            td.Core.Security.ChangePassWord cpw = new ChangePassWord();
            cpw.Text = "更改" + cp.Identity.Name + "的密码";
            if (cpw.ShowDialog() == DialogResult.OK)
            {
                var u = CG.Security.UserManager.FindByUserName(cp.Identity.Name);
                if (u.Read())
                {
                    int id = (int)u.GetValue(0);
                    if (CG.Security.UserManager.UpdatePassword(id, cpw.OldPassWord, cpw.NewPassWord) > 0)
                    {
                        XtraMessageBox.Show("密码更改成功！", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                    }
                    else
                    {
                        XtraMessageBox.Show("密码更改失败！", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                    }
                }
            }
        }
  
    }
}
